package Level02_four;

import java.util.ArrayList;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        //创建一个ArrayList对象
        ArrayList<Object> arrayList = new ArrayList<>();
        //创建5个学生对象
        Student student = new Student("小胡", 22, 1.80);
        Student student1 = new Student("小程", 21, 1.79);
        Student student2 = new Student("小向", 20, 1.78);
        Student student3 = new Student("李四", 19, 1.60);
        Student student4 = new Student("张三", 18, 1.81);
        //将学生对象添加到ArrayList中
        arrayList.add(student);
        arrayList.add(student1);
        arrayList.add(student2);
        arrayList.add(student3);
        arrayList.add(student4);
        //定义最高的身高,名字
        double max = student.getHeight();
        String name = student.getName();
        //定义最矮的身高，名字
        double min = student.getHeight();
        String name1 = student.getName();
        //遍历ArrayList，找到最高的身高和最矮的身高
        Iterator<Object> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Student student5 = (Student) iterator.next();
            if (student5.getHeight() > max) {
                max = student5.getHeight();
                name = student5.getName();
            }
            if (student5.getHeight() < min) {
                min = student5.getHeight();
                name1 = student5.getName();
            }
        }
        System.out.println("最高的身高是：" + max + "，名字是：" + name);
        System.out.println("最矮的身高是：" + min + "，名字是：" + name1);
    }
}
